import React, { useRef, useState, useEffect } from 'react'

function Example() {
    const inputE1 = useRef(null);
    const onButtonClick = () => {
        inputE1.current.value = "夜深人静";
        console.log(inputE1);
    }
    // 关键代码
    const [text, setText] = useState('jspang');
    const textRef = useRef();

    useEffect(() => {
        textRef.current = text;
        console.log(`textRef.current:`, textRef.current);
    });

    return (
        <>
            <input ref={inputE1} type="text" />
            <button onClick={onButtonClick}>在input上显示文字</button>
            <br />
            <br />
            <input value={text} onChange={(e) => setText(e.target.value)} />
        </>
    )
}

export default Example